﻿using MySql.Data.MySqlClient;

namespace iBackupExplorer.Data.mySql
{
    class mySqlDal
    {
        public static News getLatestNews()
        {
            News newsResults = null;
            const string connectionString =
                        "SERVER=instance33492.db.xeround.com;Port=14558;DATABASE=Logs;UID=news;PASSWORD=newsreader;";
            MySqlConnection connection = new MySqlConnection(connectionString);
            const string query = "SELECT * FROM `news` LIMIT 0 , 1";
            connection.Open();
            MySqlDataReader newsReader= new MySqlCommand(query, connection).ExecuteReader();


            if (newsReader.HasRows==true)
            {
                newsReader.Read();
                newsResults =new News();
                newsResults.ID = newsReader.GetInt32(0);
                newsResults.Title = newsReader.GetString(1);
                newsResults.Body = newsReader.GetString(2);
                newsResults.Link = newsReader.GetString(3);
            }

            connection.Close();
            return newsResults;
        }
    }
}
